package com.utf999.qiangmanger.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Component;

import com.utf999.qiangmanger.dao.AbstractRelationalDBDAO;
import com.utf999.qiangmanger.dao.iface.ICommodityTypeDAO;
import com.utf999.qiangmanger.entity.orm.CommodityTypeEntity;
import com.utf999.qiangmanger.exception.BizException;

/**
 * @author yinwenjie
 */
@Component("CommodityTypeDAOImpl")
public class CommodityTypeDAOImpl extends AbstractRelationalDBDAO<CommodityTypeEntity> implements ICommodityTypeDAO {

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.dao.AbstractRelationalDBDAO#getEntityClass()
	 */
	@Override
	protected Class<CommodityTypeEntity> getEntityClass() {
		return CommodityTypeEntity.class;
	}

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.dao.iface.ICommodityTypeDAO#queryCommodityTypesByCompany(java.lang.String)
	 */
	@Override
	//TODO 未进行索引优化
	public List<CommodityTypeEntity> queryCommodityTypesByCompany(String companyid) throws BizException {
		HashMap<String, Object> condition = new HashMap<String, Object>();
		condition.put("companyid", companyid);
		
		return this.queryByHqlFile("ICommodityTypeDAO.queryCommodityTypesByCompany", condition);
	}

	/* (non-Javadoc)
	 * @see com.utf999.qiangmanger.dao.iface.ICommodityTypeDAO#queryCommodityTypesByName(java.lang.String, java.lang.String)
	 */
	@Override
	//TODO 未进行索引优化
	public CommodityTypeEntity queryCommodityTypesByName(String typename, String companyid) throws BizException {
		HashMap<String, Object> condition = new HashMap<String, Object>();
		condition.put("typename", typename);
		condition.put("companyid", companyid);
		
		List<CommodityTypeEntity> types = null;
		types = this.queryByHqlFile("ICommodityTypeDAO.queryCommodityTypesByName", condition);
		if(types == null || types.size() == 0) {
			return null;
		}
		
		return types.get(0);
	}
}